﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Commonlib;
using Albon.Model;

namespace BLL
{
    public class ClientBLL
    {
        
        private readonly DAL.ClientDAL clientdal = new DAL.ClientDAL();
        /// <summary>
        /// 根据用户名获取相应的client列表
        /// </summary>
        public DataTable getClientsByUserName(string username)
        {
            return clientdal.getClient("userName ='"+username+"'");
        }
        /// <summary>
        /// 获取临时订单表中的客户名称
        /// </summary>
        public DataTable getOrderClient(string username)
        {
            string cmdstr = "select clientName from OrderInfo where userName='"+username+"' and finished=0 ";
            string clientName=SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString();
            cmdstr = "select * from Client where userName='"+username+"' and clientName='"+clientName+"'";
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }

        /// <summary>
        /// 根据客户名称获取该客户的默认绣名
        /// </summary>
        public string getNameLabel(string clientName)
        {
            DataTable dt = clientdal.getClient("clientName='" + clientName + "'");
            return dt.Rows[0]["monoName"].ToString();
        }
        public DataTable getClientByID(string clientid)
        {
           return clientdal.getClient("ID=" + clientid);
        }
        /// <summary>
        /// 更新客户的身形数据
        /// </summary>
        public bool updatePosture(Client client)
        {
            return clientdal.updatePosture(client);
        }

        /// <summary>
        /// 添加新客户
        /// </summary>
        /// <param name="client"></param>
        public bool addClients(Client client)
        {
            return clientdal.addClient(client);
        }

        /// <summary>
        /// 检查一个客户名称是否已经存在
        /// </summary>
        /// <param name="name"></param>
        public string checkName(string name, string username)
        {
            DataTable dt=clientdal.getClient("clientName='" + name + "' and userName='" + username + "'");
            if (dt.Rows.Count > 0)
            {
                return "Exists";
            }
            else {
                return "OK";
            }
        }
        /// <summary>
        /// 获取客户身形数据
        /// </summary>
        public DataTable getPosturePictureByID(string id)
        {
            return clientdal.getPosturePicture("ID="+id);
        }


        /// <summary>
        /// 为客户添加/修改新的身形数据
        /// </summary>
        public bool addPosturePicture(PosturePicture posture)
        {
            return clientdal.addPosturePicture(posture);
        }

        /// <summary>
        /// 删除客户的身形数据
        /// </summary>
        /// <param name="id"></param>
        public bool delPosturePicture(string id)
        {
            return clientdal.delPosturePicture(id);
        }


    }
}
